<?php
/**
 * Created by PhpStorm.
 * User: 毛文科
 * Date: 2018\10\28 0028
 * Time: 10:03
 */
namespace app\admin\model;
use think\Db;

class Digui
{
    private $table_name = '';
    private $data = [];
    static public function getName($table_name){
        if(!strpos($table_name,config('database.prefix'))){
            $table_name = config('database.prefix').$table_name;
        }
        $obj = new Digui();
        $obj->table_name = $table_name;
        return $obj;
    }
    public function digui($pid=0,$chen=0){
        $array = Db::table($this->table_name)->where('pid',$pid)->select();
        if($array){
            foreach ($array as $key=>$value){
                $value['chen'] = $chen;
                $this->data[] = $value;
                $this->digui($value['id'],$chen+1);
            }
        }
        return $this->data;
    }
}